package eng.jTrussSolver.Section;

import java.util.HashMap;
import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class SectionHashMap extends HashMap<String, SectionData> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public SectionHashMap ()
	{
	}



	public void addSection(SectionData sectionData) {
		this.put(sectionData.Name,sectionData);

	}

	/**
	 * Sets section to index
	 * @param currentselectedSection
	 * @param b
	 */
	public void setSection(String oldname, SectionData section) {
		this.remove(oldname);
		this.put(section.Name, section);
	}

	/**
	 * Removes Section
	 * @param currentselectedSection
	 */
	public void removeSection(String SectionName) {
		this.remove(SectionName);
	}


	/**
	 * Returns number of Sections
	 * @return
	 */
	public int getSectionsCount() {
		return this.size();
	}

	/**
	 * Code For Sections Data
	 * @param doc
	 * @return
	 */
	public Element prepareXMLElement(Document doc) {
		Element S = doc.createElement("Sections");

		for (Map.Entry<String, SectionData> entr: this.entrySet())
		{

			Element sectionElement = doc.createElement("Section");
			S.appendChild(sectionElement);

			Element g = doc.createElement("Name");
			g.appendChild(doc.createTextNode(entr.getValue().Name));			
			sectionElement.appendChild(g);

			Element c = doc.createElement("Area");
			c.appendChild(doc.createTextNode(String.valueOf(entr.getValue().Area)));
			sectionElement.appendChild(c);

			Element I = doc.createElement("Ixx");
			I.appendChild(doc.createTextNode(String.valueOf(entr.getValue().Ixx)));
			sectionElement.appendChild(I);
		}
		return S;
	}

}
